package com.myzl.web.controller.coal;

import com.myzl.coal.domain.CommandRecord;
import com.myzl.coal.service.ICommandRecordService;
import com.myzl.common.annotation.Log;
import com.myzl.common.core.controller.BaseController;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.core.page.TableDataInfo;
import com.myzl.common.enums.BusinessType;
import com.myzl.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 命令下发记录Controller
 *
 * @author myzl
 * @date 2022-10-26
 */
@RestController
@RequestMapping("/coal/commandRecord")
public class CommandRecordController extends BaseController
{
    @Autowired
    private ICommandRecordService commandRecordService;

    /**
     * 查询命令下发记录列表
     */
    @PreAuthorize("@ss.hasPermi('coal:commandRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommandRecord commandRecord)
    {
        startPage();
        List<CommandRecord> list = commandRecordService.selectCommandRecordList(commandRecord);
        return getDataTable(list);
    }

    /**
     * 导出命令下发记录列表
     */
    @PreAuthorize("@ss.hasPermi('coal:commandRecord:export')")
    @Log(title = "命令下发记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommandRecord commandRecord)
    {
        List<CommandRecord> list = commandRecordService.selectCommandRecordList(commandRecord);
        ExcelUtil<CommandRecord> util = new ExcelUtil<CommandRecord>(CommandRecord.class);
        util.exportExcel(response, list, "命令下发记录数据");
    }

    /**
     * 获取命令下发记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('coal:commandRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(commandRecordService.selectCommandRecordById(id));
    }

    /**
     * 新增命令下发记录
     */
    @PreAuthorize("@ss.hasPermi('coal:commandRecord:add')")
    @Log(title = "命令下发记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommandRecord commandRecord)
    {
        return toAjax(commandRecordService.insertCommandRecord(commandRecord));
    }

    /**
     * 修改命令下发记录
     */
    @PreAuthorize("@ss.hasPermi('coal:commandRecord:edit')")
    @Log(title = "命令下发记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommandRecord commandRecord)
    {
        return toAjax(commandRecordService.updateCommandRecord(commandRecord));
    }

    /**
     * 删除命令下发记录
     */
    @PreAuthorize("@ss.hasPermi('coal:commandRecord:remove')")
    @Log(title = "命令下发记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(commandRecordService.deleteCommandRecordByIds(ids));
    }
}
